(function($, doc) {
	$.init();
	mui('.mui-scroll-wrapper').scroll({
		scrollY: false
	});
	var cityPicker = document.getElementById("city").innerText
	$.ready(function() {
		var _getParam = function(obj, param) {
			return obj[param] || '';
		};

		var bb = new $.PopPicker();
		bb.setData([{
			text: '一年级'
		}, {
			text: '二年级'
		}, {
			text: '三年级'
		}, {
			text: '四年级'
		}, {
			text: '五年级'
		}, {
			text: '六年级'
		}]);
		var aa = doc.getElementById('aa');
		var newcls = doc.getElementById('newcls')
		aa.addEventListener('tap', function(event) {
			bb.show(function(items) {
				newcls.innerText = items[0].text;
			});

		}, false);
		var user = new $.PopPicker();
		user.setData([{
			text: '1班'
		}, {
			text: '2班'
		}, {
			text: '3班'
		}, {
			text: '4班'
		}, {
			text: '5班'
		}, {
			text: '6班'
		}]);
		var classes = doc.getElementById('classes');
		var cls = doc.getElementById("classname")
		classes.addEventListener('tap', function(event) {
			user.show(function(items) {
				cls.innerText = items[0].text;

			});

		}, false);

		var userPicker = new $.PopPicker();
		var cityPicker3 = new $.PopPicker({
			layer: 3
		});
		var school = []
		cityPicker3.setData(cityData3);
		var showCityPickerButton = doc.getElementById('showCityPicker3');
		var city = doc.getElementById('city');
		showCityPickerButton.addEventListener('tap', function(event) {
			school = []
			cityPicker3.show(function(items) {
				city.innerText = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
				if(items[2].value == "") {
					mui.toast("出现未知错误,请重新选择")
					return
				}
				showCityPickerButton.setAttribute("fkProvinceId", items[0].value)
				showCityPickerButton.setAttribute("fkCityId", items[1].value)
				showCityPickerButton.setAttribute("fkRegionId", items[2].value)
				showCityPickerButton.setAttribute("fkProvincename", items[0].text)
				showCityPickerButton.setAttribute("fkCityname", items[1].text)
				showCityPickerButton.setAttribute("fkRegionname", items[2].text)
				common.ajax("school/getSchool", {
					uid: common.uid,
					regionId: items[2].value
				}, function(data) {
					if(data.code == 200) {
						for(var i = 0; i < data.data.length; i++) {
							school.push({
								text: data.data[i].schoolName,
								id: data.data[i].id
							})
						}
						if(school != "") {
							document.getElementById("showUserPicker").style.color = "#333"
						} else {
							document.getElementById("showUserPicker").style.color = "#B2B2B2"
							document.getElementById("showUserPicker").innerText = '请输入学校名称'
						}
						userPicker.setData(school)
					} else {
						mui.toast(data.message)
					}
				})
			});
		}, false);

		var showUserPickerButton = doc.getElementById('showUserPicker');
		showUserPickerButton.addEventListener('tap', function(event) {
			if(document.getElementById("showCityPicker3").innerText == cityPicker) {
				mui.toast("地区不能为空!!!")
				return
			}
			if(school == "") {
				mui.toast("当前地区尚未开放!!!")
				return
			}
			userPicker.show(function(items) {
				showUserPickerButton.innerText = items[0].text;
				showUserPickerButton.setAttribute("name", items[0].text)
				showUserPickerButton.setAttribute("uid", items[0].id)
			});
		}, false);

	});
})(mui, document);
common.focu(".mui-input-clear", "green")

var headurl = document.getElementById("img").src
var save = document.getElementById('save');
var file = document.getElementById('file');
var back = document.getElementById('back');
var body = document.getElementById("body")
file.onclick = function() {
	body.style.display = "none"
	var imgBox = document.getElementById('imgBox');
	document.getElementsByTagName('body')[0].style.backgroundColor = '#000';
	imgBox.style.display = 'block';
	file.style.display = "none"
};
save.onclick = function() {
	imgBox.style.display = 'none';
	body.style.display = "block"
	document.getElementsByTagName('body')[0].style.backgroundColor = '#fff';
	file.style.display = "block"
	setTimeout(function() {
		if(headurl != document.getElementById("img").src) {
			document.getElementsByClassName("title-text")[0].innerText = ''
			document.getElementsByClassName("title")[0].style.padding = "34px"
			document.getElementById("formHead").style.top = "78px"
		}
	}, 10)
}
back.onclick = function() {
	plus.webview.currentWebview().reload();
}

var img = $("#img")[0].currentSrc

var diji = $("#showCityPicker3").attr("fkprovincename") + $("#showCityPicker3").attr("fkcityname") + $("#showCityPicker3").attr("fkregionname")

var base64;
var cut = new ImgClip({
	canvas: 'canvas01', // canvas id
	fileObj: 'file', // file id
	cutBtn: 'save', // cut btn id
	resultObj: 'img', // result img i
	rotateR: 'rotateR',
	cutScale: 1, // 1:1、3:4
	cutW: '300' // '数字'或者'winW'关键字，裁切宽度，随屏幕宽或自己设置
});

var showCityPicker3 = $("#showCityPicker3").text()
$(".next").on("tap", ".next-button", function() {

	//	if($(".studentname").val() == "") {
	//		$(".textprompt").css("display", "block")
	//		mui.toast("姓名不能为空")
	//		return
	//	} else if(showCityPicker3 == $("#showCityPicker3").text()) {
	//		mui.toast("请选择地区!!!")
	//		return
	//	} else if($("#showUserPicker").text().indexOf("请输入学校名称") != -1) {
	//		mui.toast("请选择学校名称!!!")
	//		return
	//	}

	var jidi = $("#showCityPicker3").attr("fkprovincename") + $("#showCityPicker3").attr("fkcityname") + $("#showCityPicker3").attr("fkregionname")

	var gender = null
	$.each($(".gender"), function(a, e) {
		if($(".gender")[a].checked) {
			gender = $(this).index()
		}
	});

	var temp = ""
	if(img == $("#img")[0].currentSrc) {
		temp = ""
	} else {
		temp = $("#img")[0].currentSrc
	}

	//	console.log(temp)
	//	console.log(jidi)

	common.ajax("student/fillInformation", {
		token: common.token,
		uid: common.uid,
		sex: gender,
		name: $(".studentname").val(), //名字
		grade: $("#newcls").text(),
		provinceId: $("#showCityPicker3").attr("fkProvinceId"), //省份id
		provinceName: $("#showCityPicker3").attr("fkprovincename"), //省名字
		cityId: $("#showCityPicker3").attr("fkCityId"), //城市id
		cityName: $("#showCityPicker3").attr("fkcityname"), //城市名字
		regionId: $("#showCityPicker3").attr("fkRegionId"),
		regionName: $("#showCityPicker3").attr("fkregionname"),
		schoolId: $("#showUserPicker").attr("uid"), //学校名字
		schoolName: $("#showUserPicker").attr("name"),
		classId: $("#showUserPicker").attr("uid"), //班级id
		className: $("#classname").text(),
		cardId: $("#cardId").val(), //学籍编号
		address: jidi,
		avatar: temp, //头像
		geTuiClientId: plus.push.getClientInfo().clientid
	}, function(data) {
		if(data.code == 200) {
			console.log(temp)
			//			alert(temp)
			common.open("likebooks.html")
		} else {
			mui.toast(data.message)
		}
	})
})